package cn.kgc.mcartoon.configration;

import cn.kgc.mcartoon.interator.AuthenticationInterator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class TokenConfigration extends WebMvcConfigurationSupport {

    @Autowired
    private AuthenticationInterator authenticationInterator;

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterator)
                .addPathPatterns("/**")
                .excludePathPatterns("/api/user/login","/api/user/getClaims")
                .excludePathPatterns("/api/home/**")
                .excludePathPatterns("/api/file/file_upload")
                .excludePathPatterns("/swagger**/**","/webjars/**","/v3/**","/doc.html");
    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");

        super.addResourceHandlers(registry);
    }
}
